class Solution {
public:
    int calculateMinimumHP(vector<vector<int>>& dungeon) {
        int m = dungeon.size();
        int n = dungeon[0].size();
        vector<vector<int>>vv(m + 1, vector<int>(n + 1, INT_MAX));
        vv[m][n - 1] = 1;
        vv[m - 1][n] = 1;
        for (int i = m - 1; i >= 0; i--)
        {
            for (int j = n - 1; j >= 0; j--)
            {
                vv[i][j] = min(vv[i + 1][j], vv[i][j + 1]) - dungeon[i][j];
                vv[i][j] = max(1, vv[i][j]);
            }

        }
        return vv[0][0];

    }
};